package com.oa.admin.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.core.PageResult;
import com.oa.admin.entity.CarApplication;
import com.oa.admin.mapper.CarApplicationMapper;
import com.oa.admin.service.ICarApplicationService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;

/**
 * <p>
 * 用车申请记录表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-02-21
 */
@Service
public class CarApplicationServiceImpl extends ServiceImpl<CarApplicationMapper, CarApplication> implements ICarApplicationService {

    private final CarApplicationMapper carApplicationMapper;

    @Autowired
    public CarApplicationServiceImpl(CarApplicationMapper carApplicationMapper) {
        this.carApplicationMapper = carApplicationMapper;
    }

    @Override
    @CommonService
    public PageResult<CarApplication> findList(Integer pageNum, Integer pageSize) {
        if (pageNum == null) {
            List<CarApplication> list = carApplicationMapper.findList();
            return new PageResult<>(list);
        } else {
            // 当前页，总条数 构造 page 对象
            Page<CarApplication> page = new Page<>(pageNum, pageSize);
            //查询
            List<CarApplication> list = carApplicationMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
     * 根据id查询
     */
    @Override
    @CommonService
    public CarApplication findCarApplicationById(String id) {
        return carApplicationMapper.findById(id);
    }
}
